package com.zendaimoney.test.simulation.action.allinpay;

import com.zendaimoney.test.simulation.action.BaseAction;
import com.zendaimoney.test.simulation.annotation.RequestCategory;
import com.zendaimoney.test.simulation.dto.request.allinpay.quick.collect.QuickCollectReq;
import com.zendaimoney.test.simulation.dto.response.allinpay.quick.collect.QuickCollectResp;
import com.zendaimoney.test.simulation.dto.response.allinpay.quick.collect.QuickCollectRespBody;
import com.zendaimoney.test.simulation.dto.response.allinpay.quick.collect.QuickCollectRespHeader;
import com.zendaimoney.test.simulation.enums.PlatformRespCode;
import com.zendaimoney.test.simulation.enums.ThirdType;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@RequestCategory(thirdType = ThirdType.ALLINPAY, bizType = "100011")
@Component("com.zendaimoney.test.simulation.action.allinpay.QuickCollectAction")
@Slf4j
public class QuickCollectAction extends BaseAction{

    @Override
    @SneakyThrows
    public String process(String requestInfo) {
        log.info("通联快捷支付代收接口");
        QuickCollectReq request = new QuickCollectReq();
        request = (QuickCollectReq)parseMessage(request, requestInfo);
        log.info("request:{}", request.toString());

        QuickCollectResp response = new QuickCollectResp();

        // header
        QuickCollectRespHeader header = new QuickCollectRespHeader();
        header.setReqSn(request.getHeader().getReqSn());
        header.setRetCode(PlatformRespCode.AllinPay.MIDDLE_2000.getHeadCode());
        header.setErrMsg(PlatformRespCode.AllinPay.MIDDLE_2000.getHeadMsg());

        // body
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        QuickCollectRespBody body = new QuickCollectRespBody();
        body.setRetCode(PlatformRespCode.AllinPay.MIDDLE_2000.getBodyCode());
        body.setErrMsg(PlatformRespCode.AllinPay.MIDDLE_2000.getBodyMsg());
        body.setSettleDay(format.format(new Date()));

        response.setHeader(header);
        response.setBody(body);

        // 签名
        // AllinpayUtil.signMsg(response.encode(), "", "");

        return response.encode();
    }
}
